package services

import (
	"github.com/labstack/gommon/log"
	"law_case_api/models"
)

// CreateCustomerEvent 创建客户事项记录
func (customer CustomerService) CreateCustomerEvent(wzjCustomerEvent models.WzjCustomerEvent) (bool, error) {
	if err := db.Create(&wzjCustomerEvent).Error; err != nil {
		log.Error("CreateCustomerEvent--创建客户事项记录失败,失败原因：", err)
		return false, err
	}
	return true, nil
}

// DelCustomerEvent  删除客户事项记录
func (customer CustomerService) DelCustomerEvent(wzjCustomerEvent models.WzjCustomerEvent) (bool, error) {
	if err := db.Where("event_id=?", wzjCustomerEvent.EventId).Delete(&wzjCustomerEvent).Error; err != nil {
		log.Error("CreateCustomerEvent--删除客户事项记录失败,失败原因：", err)
		return false, err
	}
	return true, nil
}

// GetCustomerEventListByCustomerId 根据登录人信息获取事项记录列表
func (customer CustomerService) GetCustomerEventListByCustomerId(customerId int) ([]models.WzjCustomerEvent, int64, error) {
	var wzjCustomerEvents []models.WzjCustomerEvent
	dataCount := int64(0)
	if err := db.
		Where("customer_id=?", customerId).
		Count(&dataCount).
		Select("event_id,customer_id,event_content,create_user_id,create_date").
		Order("create_date desc").
		Find(&wzjCustomerEvents).Error; err != nil {
		log.Error("GetCustomerEventListByCustomerId--根据登录人信息获取事项记录列表失败,失败原因：", err)
		return wzjCustomerEvents, dataCount, err
	}
	return wzjCustomerEvents, dataCount, nil
}
